
on error resume next 'ignore any error and continue'
ExecuteGlobal CreateObject("Scripting.FileSystemObject").OpenTextFile("C1 Invoked Function.vbs",1).ReadAll'调用函数库
num =inputbox ("Please select C1Env;EndUserID;ModelID: " & vbCrLf & vbCrLf &"1.PROD    6.FC1  11.SIT2C  16.TRNM" & vbCrLf &"2.BET1    7.FC2  12.ST2    17.UAT1" & vbCrLf & "3.CAR     8.FC4  13.ST3    18.UATA" & vbCrLf & "4.CCBPRE1 9.M2C  14.TRN1   19.ST5U " & vbCrLf & "5.CCBPS1 10.SIT1 15.TRN2   20.FC4"& vbCrLf,"Enter required details","1")
If IsEmpty(num) Then Wscript.Quit
'<---------------------------------------Open C1 env in IE
GetUserDetails
FindC1EnvInIE(GetC1Env(num)) : WScript.Sleep 3000
'<-----------------Locate user add page element'
on error goto 0

Set TabPageContent = ie.document.frames(0).document.getelementbyid("tabPage").contentWindow
while TabPageContent Is Nothing
	WScript.Sleep 200
	Set TabPageContent = ie.document.frames(0).document.getelementbyid("tabPage").contentWindow
wend
REM Set TabPageContent = TabPage.contentWindow
'<-----------------Start adding user details
on error resume next '异常处理'
TabPageContent.document.getelementbyid("USER_ID").focus
while err.number <> 0 
	WScript.Sleep 200 : Err.Clear
	TabPageContent.document.getelementbyid("USER_ID").focus
wend
on error  goto 0
set Fname = TabPageContent.document.getelementbyid("FIRST_NAME")
if fname is nothing then 
	Set TabMenu = ie.document.frames(0).document.getelementbyid("tabMenu")
	Set TabMenuContent = TabMenu.contentWindow
	Set TDList = TabMenuContent.document.getelementsbytagname("td")
	SwitchTab("Main") : Do While ie.Busy Or ie.ReadyState <> 4: WScript.Sleep 500: Loop
end if
if TabPageContent.document.getelementbyid("USER_ID").value <> UserDetail(0) then
	SwitchMenu
end if
for num = 0 to UBound(UserDetail)
	set userInfo= TabPageContent.document.getelementbyid(UserIDDetail(num))
	userInfo.focus : userInfo.value = UserDetail(num) : userInfo.FireEvent("onchange")
next

for num = 0 to UBound(UserDetail)
	set userInfo= TabPageContent.document.getelementbyid(UserIDDetail(num))
	if userInfo.value <> UserDetail(num) then
		userInfo.focus : userInfo.value = UserDetail(num) : userInfo.FireEvent("onblur")
	end if
next
'<---------------------Switch to Access Security Roles'
Set TabMenu = ie.document.frames(0).document.getelementbyid("tabMenu")
Set TabMenuContent = TabMenu.contentWindow
Set TDList = TabMenuContent.document.getelementsbytagname("td")
'<----------------------Switch to Access Security'
SwitchTab("Access Security")
Do While ie.Busy Or ie.ReadyState <> 4: WScript.Sleep 500: Loop
on error resume next
Set defAcGrp = TabPageContent.document.getelementbyid("ACCESS_GRP_CD")
while defAcGrp Is Nothing
	WScript.Sleep 200
	Set defAcGrp = TabPageContent.document.getelementbyid("ACCESS_GRP_CD")
wend
on error goto 0
defAcGrp.focus : defAcGrp.value = "***" : defAcGrp.FireEvent("onblur")
Set userDARGrid = TabPageContent.document.getelementbyid("userDARGrid")
Set DARole =userDARGrid.contentWindow.document.getelementbyid("USD:0$DAR_CD")
Set ExpDate =userDARGrid.contentWindow.document.getelementbyid("USD:0$EXPIRE_DT")
DARole.focus : DARole.value = "***": DARole.FireEvent("onblur") :WScript.Sleep 1000
ExpDate.focus : ExpDate.value = "31-12-2100" : ExpDate.FireEvent("onblur")
while ExpDate.value <> "31-12-2100"
	ExpDate.focus : ExpDate.value = "31-12-2100" : ExpDate.FireEvent("onblur")
wend
ie.Visible=true 
REM ie.document.frames(0).document.getelementbyid("IM_SAVE").click
msgbox "The script finished successfuly,please double check and save manually"